﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using DataSourceRequest = Kendo.Mvc.UI.DataSourceRequest;

using netEntity = tuReserva.Model;
using tuReserva.Service;

namespace tuReserva.com.Controllers
{
    public class CustomerController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

		public ActionResult getPartials(string partial)
		{
			return View(partial);
		}

		public JsonResult getReserveList([DataSourceRequest]DataSourceRequest request)
		{
			netEntity.User u = Session["User"] as netEntity.User;

			List<netEntity.Reserve> reserveList = new ApplicationService().getReserveList(u);

			var data = reserveList.ToDataSourceResult(request);

			return new JsonResult { Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
		}

		public JsonResult getRestaurantList([DataSourceRequest]DataSourceRequest request)
		{
			List<netEntity.Restaurant> restaurantList = new ApplicationService().getRestaurantList();

			var data = restaurantList.ToDataSourceResult(request);

			return new JsonResult { Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
		}

		[HttpPost]
		public JsonResult getNewReserve(netEntity.Restaurant restaurant)
		{
			netEntity.Reserve reserve = new netEntity.Reserve(restaurant);

			return Json(reserve, JsonRequestBehavior.AllowGet);
		}

		public JsonResult getTableList(string restaurantID)
		{
			List<netEntity.Table> tableList = new ApplicationService().getTableList(restaurantID);

			return Json(tableList, JsonRequestBehavior.AllowGet);
		}

		[HttpPost]
		public JsonResult saveReserve(netEntity.Reserve reserve)
		{
			reserve.Restaurant.User = Session["User"] as netEntity.User;

			return Json(new ApplicationService().insertReserve(reserve), JsonRequestBehavior.AllowGet);
		}

		public void rateRestaurant(netEntity.Reserve reserve, string points)
		{
			new ApplicationService().rateRestaurant(reserve, points);
		}

		[HttpPost]
		public JsonResult validateReserve(netEntity.Reserve reserve)
		{
			reserve.Restaurant.User = Session["User"] as netEntity.User;

			return Json(new ApplicationService().validateReserve(reserve), JsonRequestBehavior.AllowGet);
		}

		public JsonResult cancelReserve(string reserveID)
		{
			return Json(new ApplicationService().cancelReserve(reserveID), JsonRequestBehavior.AllowGet);
		}
    }
}
